package leetcode.code0929;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import leetcode.IDebug;
import leetcode.helper.H;

public class Solution implements IDebug {

	public int numUniqueEmails(String[] emails) {
		int ans = 0;
		Map<String, Set<String>> map = new HashMap<>();
		for (int i = 0; i < emails.length; i++) {
			String[] email = emails[i].split("[@]");
			String[] local = email[0].split("[+]");
//			String[] email = emails[i].split("\\@");
//			String[] local = email[0].split("\\+");
			String domain = email[1];
			Set<String> locals = map.getOrDefault(domain, new HashSet<>());
			String cur = local[0].replace(".", "");
			if (!locals.contains(cur)) {
				ans++;
				locals.add(cur);
			}
			map.put(domain, locals);
		}
		return ans;
	}

	@Override
	public void debug4() {
		H.compare(2, this.numUniqueEmails(H.str2array2(
				"[\"test.email+alex@leetcode.com\",\"test.e.mail+bob.cathy@leetcode.com\",\"testemail+david@lee.tcode.com\"]")));

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
